package com.caojm.mptools.commands;

import com.caojm.mptools.MiningData;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;

import java.util.Map;

public class MiningLeaderboardCommand {

    // 注册命令
    public static void register() {
    CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) ->
        dispatcher.register(
            CommandManager.literal("mp")
                .then(CommandManager.literal("leaderboard")
                    .executes(context -> {
                        ServerCommandSource source = context.getSource();

                        // 获取前10的挖掘数据
                        Map<String, Integer> top10 = MiningData.getTop10();

                        // 显示榜单
                        StringBuilder leaderboard = new StringBuilder();
                        leaderboard.append("前10名挖掘榜单:\n");
                        top10.forEach((playerName, miningData) -> {
                        leaderboard.append(playerName).append(": ").append(miningData).append(" 次\n");
                        });

                        // 返回榜单
                        source.sendFeedback(() -> Text.literal(leaderboard.toString()), false);
                        return 1;
                    })
                )
        )
    );
    }
}
